<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
$t=isset($_GET['t'])?intval($_GET['t']):0;
$table=($t==0?'rate8':'rate9');
$conf =new Config();
$ui = new ui();
$tpl = new Template2();
$fieldArr = array("method" => "5", "gametype" => "0", "round" => "0", "lotto_id" => "0", "betcontent" => "", "orate" => "", "nrate" => "", "pagename" => "2", "paperopen" => date( "Y-m-d" ) );
$tpl->load( "main", "rate8.htm" );
$tpl->set( "cchinayear", intval( $conf->get( "chinayear" ) ) );
$disk = "a";
if ( isset( $_GET['disk'] ) )
{
    $disk = $_GET['disk'];
}
else if ( isset( $_POST['disk'] ) )
{
    $disk = $_POST['disk'];
}
include( "admin_menu.php" );
include( "rate_menu.php" );
srateMenu( "srate8", $disk );
$tpl->set("t",($t==0?'<input type="button" name="B1" disabled="disabled" value="三全中" />&nbsp;<input type="button" name="B2" onclick="document.location=\'?op=admin&fp=srate8&disk='.$disk.'&t=1\'" value="四全中" />':'<input type="button" name="B1" onclick="document.location=\'?op=admin&fp=srate8&disk='.$disk.'&t=0\'" value="三全中" />&nbsp;<input type="button" disabled="disabled" name="B2" value="四全中" />'));
$tpl->set( "action", "op.php?op=admin&fp=srate8&disk={$disk}&t=".$t );
if ( $disk == "a" )
{
    $setRateFlag = true;
}
else
{
    $setRateFlag = false;
}
$idisk = strpos( "0abcd", $disk );
if ( ispost( ) )
{
    $fields = array();
    if ( $setRateFlag )
    {
        $sqlRate = "!!SELECT * FROM {$table} WHERE lotto_id = 0 and disk={$idisk} LIMIT 0,1";
        $rsRate = getdb( $sqlRate );
        $setRateFlag = !$rsRate->eof;
    }
    $i = 1;
    while ( $i < 50 )
    {
        $ii = d2( $i );
        $temp = floatval( $_POST["r0_".$ii] );
        $idx = "r".$ii;
        $fields[$idx] = $temp;
        if ( $setRateFlag && $rsRate->f[$idx] != $temp )
        {
            $fieldArr['betcontent'] = "三全中:{$disk}盘:{$ii}";
            $fieldArr['orate'] = $rsRate->f[$idx];
            $fieldArr['nrate'] = $temp;
            setRateRecord( $fieldArr );
        }
        ++$i;
    }
    db_update( $table, $fields, "lotto_id=0 and disk={$idisk}" );
}
$rs = getdb( "!!select * from {$table} where lotto_id=0 and disk={$idisk}" );
if ( $rs->eof )
{
    getdb( "insert into {$table} (lotto_id,disk) values (0,{$idisk})" );
    $rs = getdb( "!!select * from {$table} where lotto_id=0 and disk={$idisk}" );
}
$i = 1;
while ( $i < 50 )
{
    $ii = d2( $i );
    $tpl->set( "r0_".$ii, trimfloat( $rs->f["r".$ii], 1 ) );
    ++$i;
}
$rs->close();
$tpl->show( "main" );
?>